package com.triones.api.controller.api;

import cn.dev33.satoken.annotation.SaIgnore;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.triones.api.entity.CryptoInCommonUseAddressDO;
import com.triones.api.entity.bo.MemberBO;
import com.triones.api.entity.bo.UpdatePwdBO;
import com.triones.api.entity.vo.CryptoInCommonUseAddressVO;
import com.triones.api.entity.vo.CustomInviteRecordVO;
import com.triones.api.entity.vo.CustomPublicizeMemberWalletVO;
import com.triones.api.entity.vo.CustomWordOrderVO;
import com.triones.api.service.MemberService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * api - 用户会员相关接口
 *
 * @Author: triones
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/member")
public class ApiMemberController extends BaseController {

    private final MemberService memberService;

    /**
     * 检查是否具备白标用户申请条件
     * true:具备、false:不具备
     * @return
     */
    @GetMapping("/checkHaveApplyVip")
    public R<Boolean> checkHaveApplyVip() {
        return R.ok("操作成功！",memberService.checkHaveApplyVip());
    }

    /**
     * 白标用户申请
     * @return
     */
    @PostMapping("/applyVip")
    public R<Void> applyVip() {
        memberService.apiApplyVip();
        return R.ok("申请成功！");
    }

    /**
     * 推广中心用户信息和钱包信息
     * @return
     */
    @GetMapping("/publicizeWalletInfo")
    public R<CustomPublicizeMemberWalletVO> publicizeWalletInfo() {
        return R.ok(memberService.publicizeWalletInfo());
    }

    /**
     * 个人中心 -常用地址列表（分页）
     * @return
     */
    @GetMapping("/crypto/inCommonUseAddress")
    public TableDataInfo<CryptoInCommonUseAddressVO> inCommonUseAddressPageList(PageQuery pageQuery) {
        return memberService.inCommonUseAddressPageList(pageQuery);
    }

    /**
     * 个人中心 -常用地址新增
     * @return
     */
    @PostMapping("/crypto/inCommonUseAddress")
    public R<Void> addInCommonUseAddress(@Validated @RequestBody CryptoInCommonUseAddressDO dto) {
        return toAjax(memberService.addInCommonUseAddress(dto));
    }

    /**
     * 个人中心 -常用地址详情
     * @return
     */
    @GetMapping("/crypto/inCommonUseAddress/{id}")
    public R<CryptoInCommonUseAddressVO> inCommonUseAddressDetail(@NotNull(message = "主键不能为空") @PathVariable("id") Long id) {
        return R.ok(memberService.inCommonUseAddressDetail(id));
    }

    /**
     * 个人中心 -常用地址修改
     * @return
     */
    @PutMapping("/crypto/inCommonUseAddress")
    public R<Void> editInCommonUseAddress(@Validated @RequestBody CryptoInCommonUseAddressDO dto) {
        return R.fail("该接口停用");
    }

    /**
     * 推广中心 -用户列表（分页）
     * @return
     */
    @GetMapping("/invite/memberPageList")
    public TableDataInfo<CustomInviteRecordVO> apiInviteMemberPageList(String isEffective,PageQuery pageQuery) {
        return memberService.apiInviteMemberPageList(isEffective,pageQuery);
    }

    /**
     * 个人中心 -常用地址删除
     * @return
     */
    @DeleteMapping("/crypto/inCommonUseAddress/{id}")
    public R<Void> delInCommonUseAddress(@NotNull(message = "主键不能为空") @PathVariable("id") Long id) {
        memberService.delInCommonUseAddress(id);
        return R.ok("操作成功");
    }

    /**
     * 个人中心 -修改登录密码
     * @return
     */
    @SaIgnore
    @PutMapping("/updatePwd")
    public R<Void> updatePwd(@Validated @RequestBody UpdatePwdBO bo) {
        memberService.updatePwd(bo);
        return R.ok("操作成功");
    }
}
